﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.DAL;
using System.IO;

public partial class FilesPage_FileSelect : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        fileManage_fileSelect.Visible = false;
    }
    protected void DocName_Click(object sender, EventArgs e)
    {
        fileManage_fileSelect.Visible = true;
        LinkButton btn = sender as LinkButton;
        int rowindex = ((GridViewRow)btn.NamingContainer).RowIndex;
        LabelFileName.Text = (GridViewShowFile.Rows[rowindex].Cells[1].FindControl("DocName") as LinkButton).Text;
        LabelAddress.Text = (GridViewShowFile.Rows[rowindex].Cells[2].FindControl("LabelAddress") as Label).Text;
        TextBoxMeno.Text =( GridViewShowFile.Rows[rowindex].Cells[5].FindControl("DocMemo")as Label).Text;
        LabelCreateTime.Text = (GridViewShowFile.Rows[rowindex].Cells[4].FindControl("DocCreatDate") as Label).Text;
    }
    protected void ImageButtonSelect_Click(object sender, ImageClickEventArgs e)
    {
        string allName = TextBoxAllFileName.Text.Trim();
        string name = TextBoxName.Text.Trim();
        string userName = TextBoxCreateUserName.Text.Trim();
        List<v_SelectAllDocumentManage> Files = new List<v_SelectAllDocumentManage>();

        if (!string.IsNullOrEmpty(allName) || !string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(userName))
            Files = FileOperationBLL.SelectAllDoc(allName, name, userName);

        //绑定gridvi
        GridViewShowFile.DataSource = Files;
        GridViewShowFile.DataBind();
        //清空保存的数据
        allName = "";
        name = "";
        userName = "";
    }
    protected void LinkButtonFileUpload_Click(object sender, EventArgs e)
    {
        //保存本地的文件名
        string filename = LabelAddress.Text.Substring(LabelAddress.Text.LastIndexOf("\\"));
        //文件的物理路径
        string filePath = Server.MapPath("~/UserFiles") + filename;
        //清空HTTP 的标头
        Response.Clear();
        Response.ClearHeaders();
        //下载的时候保存的默认文件名
        Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
        //输出到客户端
        Response.TransmitFile(filePath);
    }
}